home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-12-02 | 5.1 KB | 175 lines | [TEXT/????] |
- NB. interest functions
- NB.
- NB. drn accint intlist accumulate intlist for duration
- NB. intexpand intlist expand modal intlist
- NB. frq intm intrate convert single intrate to modal
- NB. frq intmodal intlist convert intlist to modal rate
- NB. frq intrep intlist expand intlist
- NB. frq vrep intlist expand intlist to discount rates
- NB. len stretch list stretch list to length len
- NB.
- NB. accpay dat accumulate payments
- NB. opt accndx dat accumulate indexed payments.
- NB.
- NB. amort dat calculate amortization table
- NB. npv dat net present value
- NB. osb dat outstanding loan balance
- NB. ruleof78 term outstanding balance on rule of 78
- NB. int vt term v to the power t
- NB.
- NB. where:
- NB. <intlist> is an interest list, e.g. 0.09 5 0.08 3 0.075
- NB. <intrate> is a single interest rate, e.g. 0.075
-
- t=. 'accint accndx accpay amort intexpand intm intmodal intrep'
- t=. t,' npv osb ruleof78 stretch vrep vt'
- SCRIPTNAMES=: t
-
- accint=: */\ @ (1&,) @ (stretch >: @ intexpand)
- intm=: <: @ ((^%)~ >:)
- intrep=: '1 intrep y.' : 'intexpand x. intmodal y.'
- stretch=: [ $ ] , ($ ,: @ {:)
- vrep=: % @ >: @ intrep
-
- aa=: a=. ;@:(2&{.@(,&1)&.>)@((~: <.) <;.1 ])
- intmodal=: *`intm @. (1&>@]"0) (a f.)
- intexpand=: 1&>.@(#~ 1&|.@(1&>)) # (#~ 1&>)
-
- NB. accndx
- accndx=: 0 : 0
- NB. accumulate indexed payments
- NB. initial payment rate is 1 per annum.
- NB. dat= imm 0=advance, 1=arrears
- NB. frq payment frequency 12=monthly
- NB. int annual interest rate
- NB. yrs number of years
- NB. ndx indexation rate (annual increases)
- NB. opt= 0 return end year values only (default)
- NB. 1 return all values
- NB.
- NB. e.g. accndx 1;12;0.10 5 0.09;24;0.025
- NB. = 24 years payments of 1 indexed at 2.5%
- NB. payable monthly in arrears
- NB. interest 10% for 5 years, 9% thereafter
- 0 accndx y.
- :
- $.=. (5=#y.) >@{ ({.;}.) $.
- 'imm frq int yrs ndx'
- 'mfiyn'=. y.
- len=. f*y
- n=. intexpand n
- n=. y$0,n,y${:n
- i=. f intrep i
- i=. len$i,len${:i
- p=. f#(%f)**/\1+n
- j=. */\len$1+i
- r=. j*+/\p%m}.1,(<:m)}.j
- (len$x.>.(-f){.1)#r
- )
-
- NB. accpay
- accpay=: 0 : 0
- NB. dat= imm 0=advance, 1=arrears
- NB. frq payment frequency 12=monthly
- NB. int annual interest rate
- NB. pay payments per annum
- NB.
- NB. e.g. accpay 1;12;0.10 5 0.09;24#1
- NB. = 24 years payments of 1 payable monthly in arrears
- NB. interest 10% for 5 years, 9% thereafter
- $.=. (4=#y.) >@{ ({.;}.) $.
- 'imm frq int pay'
- 'mfip' =. y.
- len=. $p=. f#p%f
- j=. }. len accint f intmodal i
- r=. j*+/\p%m}.1,(m-1)}.j
- (len$(-f){.1)#r
- )
-
- NB. amort
- amort=: 0 : 0
- NB. Generates an amortization table for loan of 1.
- NB. payments are assumed to be made in arrears.
- NB.
- NB. y. has 3 elements:
- NB. frq = payment frequency (e.g. 1=annual, 12=monthly)
- NB. int = decimal nominal interest rate per annum.
- NB. yrs = number of years of loan
- NB.
- NB. result is a matrix: pay osb ip pp
- NB. psy = level payment necessary to amortize the loan
- NB. osb = outstanding balance before each payment
- NB. ip = interest portion of each payment
- NB. pp = principal portion of each payment
- NB.
- NB. e.g amort 12;0.125;25
- NB. = 25 year loan payable monthly at 12.5%
- $.=. (3=#y.) >@{ ({.;}.) $.
- 'frq int yrs'
- 'fiy'=. y.
- len=. f*y
- i=. <:(>:i)^%f
- vn=. */\1,len$%>:i
- osb=. osb%{.osb=.|.-.}.vn
- pay=. %+/}.vn
- pp=. pay-ip=. osb*i
- pay,.osb,.ip,.pp
- )
-
- NB. npv
- npv=: 0 : 0
- NB. Net present values
- NB. y. has 4 elements:
- NB. imm = 0=advance, 1=arrears
- NB. frq = payment frequency (e.g. 1=annual, 12=monthly)
- NB. int = annual earned interest rate
- NB. pay = payments per annum
- NB.
- NB. e.g. npv 1;12;0.10 5 0.09;24#1
- NB. = 24 years payments of 1 payable monthly in arrears
- NB. interest 10% for 5 years, 9% thereafter
- $.=. (4=#y.) >@{ ({.;}.) $.
- 'imm frq int pay'
- 'mfip'=. y.
- len=. $p=. f#p%f
- i=. len$i,len${:i=. f intrep i
- +/p*m}.1,(<:m)}.*/\len$%>:i
- )
-
- NB. osb
- osb=: 0 : 0
- NB. Outstanding balances on loan repaid by level instalments
- NB. y. = int,yrs
- $.=. (2=#y.) >@{ ({.;}.) $.
- 'int yrs'
- 'iy'=. y.
- $.=. >(*i){ ({.;}.) $.
- (|. i. >:y)%y
- (%{.)|.-.*/\1,y$%>:i
- )
-
- NB. ruleof78
- NB. Generates outstanding balances on rule of 78
- ruleof78=: (% {.) @ (|.@(+/\)@i.@>:)
-
- NB. vt
- vt=: 0 : 0
- :
- NB. int vt t
- NB. v to the power t
- NB. t = durations
- NB. int = interest rate
- NB.
- NB. e.g. 0.065 5 0.05 vt 5 6 7 8
- NB. = discount at durations 5 6 7 8
- NB. interest 6.5% for 5 years, 5% thereafter
- $.=. >(1<#x.){ ({.;}.) $.
- y.^~%>:x.
- i=. intexpand x.
- len=. >:>.>./t=. ,y.
- v=. 1,*/\len$v,len${:v=. %>:i
- r=. (w=. <.t) { v
- r [ $.=. $. #~ *./0=f=. t-w
- ($y.)$r* f^~w{ (}.%}:)v
- )
-